﻿using ASmile.Com;
using ASmile.Com.DictCom;
using ASmile.DBModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASmile.Win
{
    public static class DictHelper
    {
        static IDictHelperBLL BLLObj { get; } = ObjectFactory.GetObject<IDictHelperBLL>("DictHelperBLL");

        public static List<Dict_Area> GetAreas(string pCode, string searchCode)
        {
            return
            BLLObj.GetAreas(new ArgGetAreas
            {
                PCode = pCode,
                SearchVal = searchCode
            }).data;
        }

        public static string GetBNoStr(int bNoType)
        {
            return BLLObj.GetBNoStr(bNoType).data;
        }

        public static List<Dict_Common> GetDicts(ArgDictSearch arg)
        {
            return BLLObj.GetDicts(arg).data;
        }

        public static Dict_Common GetDict(short typeNo, string code)
        {
            return GetDicts(new ArgDictSearch
            {
                DictType = typeNo,
                DictCode = code
            }).FirstOrDefault();
        }
        /// <summary>
        /// 根据指定类型 指定编码获取字典数据
        /// </summary>
        public static Dict_Common GetDict(EmDictType type, string code)
        {
            return GetDict((short)type, code);
        }

        public static List<Dict_Common> GetDicts(params short[] types)
        {
            return GetDicts(new ArgDictSearch
            {
                DictTyps = types
            });
        }

        public static List<Dict_Common> GetDicts(params EmDictType[] types)
        {
            return GetDicts(types.Select(s => (short)s).ToArray());
        }

        public static List<Dict_Common> GetDicts(short type, string searchVal = null)
        {
            return GetDicts(new ArgDictSearch
            {
                DictType = type,
                SearchVal = searchVal
            });
        }

        public static List<Dict_Common> GetDicts(EmDictType type, string searchVal = null)
        {
            return GetDicts((short)type, searchVal);
        }

        public static RetEasyCode GetEasyCode(string word)
        {
            return BLLObj.GetEasyCode(word).data;
        }

        public static string GetPYCode(string word)
        {
            return GetEasyCode(word)?.PY;
        }

        public static string GetWBCode(string word)
        {
            return GetEasyCode(word)?.WB;
        }

        public static string GetPY_WB(string word)
        {
            var r = GetEasyCode(word);
            if (r == null) return null;
            return $"{r.PY};{r.WB}";
        }
    }
}